<?php
/**
 * OM适配器缓存类
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the MIT-LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 */
namespace OM\Lib;

use Exception;


final class Cache
{
    private  $m_cache = 'cache/';
    protected static $_instance = null; //缓存实例

    public function __construct( $dir )
    {
        if( $dir )
            $this->m_cache = $dir ;
    }
    /**
     * 实例缓存操作类
     * 
     * @param  string $key  缓存的key
     * @param  mixed  $data 设置缓存的值
     * @return mixed          返回类型
     */
    protected function _cache( $key, $data )
    {
        return false;
    }

    /**
     * 获取缓存实例
     * 
     * @return 
     */
    public static function instance( $dir = null )
    {
        if( !self::$_instance )
            self::$_instance = new self( $dir );
        return self::$_instance;
    }

    public static function add( $key, $data )
    {
        $Cacheobj = self::instance();
        $Cacheobj->_cache( $key, $data );
    }

    public static function read( $key )
    {
        $Cacheobj = self::instance();
        return $Cacheobj->_cache( $key, false );
    }

    public static function remove( $key )
    {
        $Cacheobj = self::instance();
        $Cacheobj->_cache( $key, null );
    }

    public static function update( $key, $data)
    {
        $Cacheobj = self::instance();
        $Cacheobj->_cache( $key, $data );
    }
}
